<template>
  <div>
    <el-card>
        <el-row type="flex" justify="end">
        <el-tooltip content="打印岗位信息">
          <router-link :to="{path:`/employees/print/${this.$route.params.id}`,query:{type:'jobInfo'}}">
            <i class="el-icon-printer" />
          </router-link>
         
        </el-tooltip>
    </el-row>
      <el-form ref="ruleForm" :model="ruleForm">
        <div>基础信息</div>
        <el-form-item label="岗位" prop="post" label-width="200px">
          <el-input
            v-model="ruleForm.post"
            style="width: 400px"
            placeholder="请输入岗位名称"
          />
        </el-form-item>
        <el-form-item
          label="转正状态"
          prop="stateOfCorrection"
          label-width="200px"
        >
          <el-select
            v-model="ruleForm.stateOfCorrection"
            placeholder="请选择"
            disabled
          >
            <el-option
              v-for="item in employeeEnum.positiveType"
              :key="item.value"
              :label="item.value"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="职级" prop="rank" label-width="200px">
          <el-input
            v-model="ruleForm.rank"
            style="width: 400px"
            placeholder="请输入职级"
          />
        </el-form-item>

        <el-form-item
          label="转正评价"
          prop="correctionEvaluation"
          label-width="200px"
        >
          <el-input
            v-model="ruleForm.correctionEvaluation"
            style="width: 600px"
            type="textarea"
            placeholder="请输入转正评价"
          />
        </el-form-item>
        <!-- reportId 汇报对象 -->
        <el-form-item label="汇报对象" prop="reportName" label-width="200px">
          <el-select v-model="ruleForm.reportName" placeholder="请选择">
            <el-option
              v-for="item in depts"
              :key="item.id"
              :label="item.username"
              :value="item.username"
            >
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="HRBP" prop="hrbp" label-width="200px">
          <el-select v-model="ruleForm.hrbp" placeholder="请选择">
            <el-option
              v-for="item in depts"
              :key="item.id"
              :label="item.username"
              :value="item.username"
            >
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item
          label="调整司龄（天）"
          prop="adjustmentAgedays"
          label-width="200px"
        >
          <el-input
            v-model="ruleForm.adjustmentAgedays"
            placeholder="请输入密码"
            style="width: 400px"
          />
        </el-form-item>

        <el-form-item
          label="首次参加工作时间"
          prop="workingTimeForTheFirstTime"
          label-width="200px"
        >
          <el-date-picker
            v-model="ruleForm.workingTimeForTheFirstTime"
            type="date"
            placeholder="选择日期"
          >
          </el-date-picker>
        </el-form-item>

        <el-form-item
          label="调整工龄"
          prop="adjustmentOfLengthOfService"
          label-width="200px"
        >
          <el-input
            v-model="ruleForm.adjustmentOfLengthOfService"
            placeholder="请输入工龄"
            disabled
            style="width: 400px"
          />
        </el-form-item>
        <div>合同信息</div>
        <el-form-item
          label="首次合同开始时间"
          prop="initialContractStartTime"
          label-width="200px"
        >
          <el-date-picker
            v-model="ruleForm.initialContractStartTime"
            type="date"
            placeholder="选择日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item
          label="首次合同结束时间"
          prop="firstContractTerminationTime"
          label-width="200px"
        >
          <el-date-picker
            v-model="ruleForm.firstContractTerminationTime"
            type="date"
            placeholder="选择日期"
          >
          </el-date-picker>
        </el-form-item>

        <el-form-item
          label="现合同开始时间"
          prop="currentContractStartTime"
          label-width="200px"
        >
          <el-date-picker
            v-model="ruleForm.currentContractStartTime"
            type="date"
            placeholder="选择日期"
          >
          </el-date-picker>
        </el-form-item>

        <el-form-item
          label="现合同结束时间"
          prop="closingTimeOfCurrentContract"
          label-width="200px"
        >
          <el-date-picker
            v-model="ruleForm.closingTimeOfCurrentContract"
            type="date"
            placeholder="选择日期"
          >
          </el-date-picker>
        </el-form-item>

        <el-form-item
          label="合同期限"
          prop="contractPeriod"
          label-width="200px"
        >
          <el-select v-model="ruleForm.contractPeriod" placeholder="请选择">
            <el-option
              v-for="item in employeeEnum.contractPeriod"
              :key="item.id"
              :label="item.value"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="续签次数" prop="renewalNumber" label-width="200px">
          <el-select v-model="ruleForm.renewalNumber" placeholder="请选择">
            <el-option
              v-for="item in employeeEnum.renewalCount"
              :key="item.id"
              :label="item.value"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>

        <div>招聘信息</div>
        <el-form-item
          label="其他招聘渠道"
          prop="otherRecruitmentChannels"
          label-width="200px"
        >
          <el-select
            v-model="ruleForm.otherRecruitmentChannels"
            placeholder="请选择"
          >
            <el-option
              v-for="item in employeeEnum.resumeSource"
              :key="item.value"
              :label="item.value"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item
          label="招聘渠道"
          prop="recruitmentChannels"
          label-width="200px"
        >
          <el-select
            v-model="ruleForm.recruitmentChannels"
            placeholder="请选择"
          >
            <el-option
              v-for="item in employeeEnum.resumeSource"
              :key="item.id"
              :label="item.value"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item
          label="社招/校招"
          prop="socialRecruitment"
          label-width="200px"
        >
          <el-select v-model="ruleForm.socialRecruitment" placeholder="请选择">
            <el-option
              v-for="item in employeeEnum.hireSourceType"
              :key="item.value"
              :label="item.value"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="推荐企业/人" label-width="200px">
          <el-input
            v-model="ruleForm.recommenderBusinessPeople"
            style="width: 200px"
            placeholder="请输入企业/人"
          />
        </el-form-item>
        <el-form-item label-width="200px">
          <el-button type="primary" @click="save()">保存更新</el-button>
          <el-button @click="$router.back()">返回</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>
<script>
import { getJobDetail, updateJob, getSimple } from "@/api/employees";
import employeeEnum from "@/api/constant/employees";
export default {
  data() {
    return {
      //  employeeEnum: employeeEnum,
      employeeEnum, //ES6写法
      userId: "", //员工id
      depts: [], // HRBP和汇报对象使用的选择下拉框
      ruleForm: {
        //TODO
        adjustmentAgedays: "", //调整司龄天
        adjustmentOfLengthOfService: "", //	调整工龄天
        closingTimeOfCurrentContract: "", //现合同结束时间
        companyId: "", //公司ID
        contractDocuments: "", //合同文件
        contractPeriod: "", //合同期限
        correctionEvaluation: "", //转正评价
        currentContractStartTime: "", // 现合同开始时间
        firstContractTerminationTime: "", //首次合同结束时间
        hrbp: "", //      HRBP
        initialContractStartTime: "", //  首次合同开始时间
        otherRecruitmentChannels: "", // 其他招聘渠道
        post: "", // 岗位
        rank: "", //职级
        recommenderBusinessPeople: "", //	推荐企业人
        recruitmentChannels: "", // 招聘渠道
        renewalNumber: "", //续签次数
        reportId: "", //汇报对象
        reportName: "", //   汇报对象
        socialRecruitment: "", //社招校招
        stateOfCorrection: "", //  转正状态
        taxableCity: "", //    纳税城市
        userId: "", //   员工ID
        workMailbox: "", // 工作邮箱
        workingCity: "", // 工作城市
        workingTimeForTheFirstTime: "", //首次参加工作时间
      },
      activeName: "first",
    };
  },
  created() {
    this.userId = this.$route.params.id;
    this.getJobDetail();
    this.getSimple();
  },
  methods: {
    // 根据每个人不同的id获取员工的岗位信息
    async getJobDetail() {
      this.ruleForm = await getJobDetail(this.userId);
      console.log(this.ruleForm);
    },
    // 获取员工简单个人信息
    async getSimple() {
      this.depts = await getSimple();
    },

    // 保存更新
    async save() {
      try {
        await this.$confirm("确定要修改信息吗？");
        await updateJob({id:this.userId,...this.ruleForm});
        this.$message.success("保存更新信息成功");
      } catch (error) {
        console.log(error);
      }
    },
  },
};
</script>